
angular.module('calculateSkuPrice', ['baisonDb', 'baisonService'])
//商品价格
.factory('SkuPrice', ['$q', 'dbSelect', 'apiService', '$rootScope', 'timeStamp2String',function ($q, dbSelect, apiService, $rootScope,timeStamp2String) {
       //获取商品表的定价序号
       var get_shop_price_index = function(shop_code){
           var sql = 'select ShopPriceIndex,ShopRebate from PosShop where ShopCode ="' + shop_code + '"' ;
           return dbSelect('YsPos', sql);
       };
       //获取定价商品表信息 根据skucode
       var get_pricing_info = function(SkuCode){
           var sql = 'select * from PosSku_pricing where SkuCode = "' + SkuCode + '"' ;
           return dbSelect('YsPos', sql);
       };
       
        //是否有调价
        var check_adjust = function(shop_code,sku_code){
            var _time = timeStamp2String(0, 'datetime');
            var sql = 'select * from PosSku_adjust_price p'
            + ' inner join PosSku_adjust_price_detail r on r.AdjustId = p.AdjustId '
            +' where p.Start_Date <= "' + _time + '" and p.End_Date >= "' + _time + '" and ( p.Shop_Code ="' + shop_code + '" or p.Shop_Code = "")'
            + ' and r.SkuCode = "' + sku_code + '"'
            +' order by p.Lastchanged desc limit 1' ;
            //console.log(sql);
            return dbSelect('YsPos', sql);
        };
        //是否有调价根据skucode
        var check_adjust_detail = function(SkuCode,AdjustId){
            var sql = 'select * from PosSku_adjust_price_detail where AdjustId = "' + AdjustId + '" and SkuCode = "' + SkuCode + '"' ;
            return dbSelect('YsPos', sql);
        };
        
        return {
            check_adjust:check_adjust,
            check_adjust_detail:check_adjust_detail,
            get_shop_price_index:get_shop_price_index,
            get_pricing_info:get_pricing_info
        };
    }])